﻿using System.Diagnostics;

namespace DimensionsHelper.LanguageService.Syntax;

public class ResumeStatement : Statement
{
    private readonly SyntaxToken _resumeKeywordToken;
    private SyntaxToken? _nextKeywordToken;

    internal ResumeStatement(SyntaxToken resumeKeyword, SyntaxNode? parent) :
        base(SyntaxKinds.ResumeStatement, parent)
    {
        SetChildField(ref _resumeKeywordToken, resumeKeyword);
    }

    public SyntaxToken ResumeKeywordToken => _resumeKeywordToken;

    public SyntaxToken? NextKeywordToken => _nextKeywordToken;


    public void Update(SyntaxToken nextKeywordToken)
    {
        SetChildNullableField(ref _nextKeywordToken, SyntaxToken.IsNullOrEmpty, nextKeywordToken);
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, ResumeKeywordToken, NextKeywordToken);
    }
}


public static partial class NodeFactory
{
    public static ResumeStatement CreateResumeStatement(SyntaxNode? parent, SyntaxToken resumeKeywordToken,
        SyntaxToken? nextKeywordToken)
    {
        Debug.Assert(SyntaxToken.IsNullOrEmpty(resumeKeywordToken) ||
                     resumeKeywordToken.IsNode(SyntaxKinds.ResumeKeywordToken));
        Debug.Assert(nextKeywordToken == null || nextKeywordToken.IsNode(SyntaxKinds.NextKeywordToken));
        ResumeStatement stat = new(resumeKeywordToken, parent);
        if (nextKeywordToken != null)
        {
            stat.Update(nextKeywordToken);
        }

        return stat;
    }
}